package com.zbxx.practice.designpattern.proxy.dynamicproxy;

import com.zbxx.practice.designpattern.proxy.BusinessObject;
import com.zbxx.practice.designpattern.proxy.BusinessService;

import java.lang.reflect.Proxy;

/**
 * @author 万仁杰
 * @date 2019/05/31
 */
public class Main {

    public static void main(String[] args) {
        //jdk dynamic proxy
        BusinessObject businessObject = new BusinessObject();
        BusinessService proxyObject =(BusinessService) Proxy
                .newProxyInstance(businessObject.getClass().getClassLoader(),businessObject.getClass().getInterfaces(),
                        new JdkProxyInvocationHandler(businessObject));
        proxyObject.doService();

        //cglib proxy
        BusinessService cglibProxyObject = (BusinessObject)new CglibProxy().getProxyClass(BusinessObject.class);
        cglibProxyObject.doService();



    }

}
